//
//  BaseRequest.h
//  BaseProject
//
//  Created by Macx on 2018/2/22.
//  Copyright © 2018年 Gavin. All rights reserved.
//

#import <Foundation/Foundation.h>
//#import <AFNetworking/AFNetworking.h>
#import <AFNetworking/AFHTTPSessionManager.h>

typedef NS_ENUM(NSInteger,RequestType) {
    RequestTypeRefresh,    //下拉刷新
    RequestTypeAdd         //上拉加载
};

NS_ASSUME_NONNULL_BEGIN

NS_ENUM(NSInteger) {
    RequestValidationErrorInvalidStatusCode = -8,
    RequestValidationErrorInvalidJSONFormat = -9,
};
    

typedef NS_ENUM(NSInteger, RequestMethod) {
        RequestMethodGET = 0,
        RequestMethodPOST,
        RequestMethodHEAD,
        RequestMethodPUT,
        RequestMethodDELETE,
        RequestMethodPATCH,
};

typedef NS_ENUM(NSInteger, RequestSerializerType) {
        RequestSerializerTypeHTTP = 0,
        RequestSerializerTypeJSON,
};
    
typedef NS_ENUM(NSInteger, ResponseSerializerType) {
        ResponseSerializerTypeHTTP,
        ResponseSerializerTypeJSON,
        ResponseSerializerTypeXMLParser,
};
    
typedef NS_ENUM(NSInteger, RequestPriority) {
        RequestPriorityLow = -4L,
        RequestPriorityDefault = 0,
        RequestPriorityHigh = 4,
};

    
@class BaseRequest;
    
typedef void (^AFConstructingBlock)(id<AFMultipartFormData> formData);
typedef void(^RequestCompletionBlock)(__kindof BaseRequest *request);
typedef void (^AFURLSessionTaskProgressBlock)(NSProgress *);
    
@interface BaseRequest : NSObject

@property (nonatomic) NSInteger tag;

@property (nonatomic, strong, readonly) NSURLSessionTask *requestTask;

@property (nonatomic, strong, readonly) NSURLRequest *currentRequest;

@property (nonatomic, strong, readonly) NSURLRequest *originalRequest;

@property (nonatomic, strong, readonly) NSHTTPURLResponse *response;

@property (nonatomic, readonly) NSInteger responseStatusCode;

@property (nonatomic, strong, readonly, nullable) NSDictionary *responseHeaders;

@property (nonatomic, strong, readonly, nullable) NSData *responseData;

@property (nonatomic, strong, readonly, nullable) NSString *responseString;

@property (nonatomic, strong, readonly, nullable) id responseObject;

@property (nonatomic, strong, readonly, nullable) id responseJSONObject;

@property (nonatomic, strong, readonly, nullable) NSError *error;

@property (nonatomic, readonly, getter=isCancelled) BOOL cancelled;

@property (nonatomic, readonly, getter=isExecuting) BOOL executing;

@property (nonatomic, copy, nullable) RequestCompletionBlock successCompletionBlock;

@property (nonatomic, copy, nullable) RequestCompletionBlock failureCompletionBlock;

@property (nonatomic, copy, nullable) AFConstructingBlock constructingBodyBlock;

@property (nonatomic, strong, nullable) NSString *resumableDownloadPath;

@property (nonatomic, copy, nullable) AFURLSessionTaskProgressBlock resumableDownloadProgressBlock;

@property (nonatomic) RequestPriority requestPriority;

- (void)setCompletionBlockWithSuccess:(nullable RequestCompletionBlock)success
                              failure:(nullable RequestCompletionBlock)failure;
- (void)clearCompletionBlock;

//- (void)start;

//- (void)stop;

- (void)startWithCompletionBlockWithSuccess:(nullable RequestCompletionBlock)success
                                    failure:(nullable RequestCompletionBlock)failure;

- (NSString *)baseUrl;

- (NSString *)requestUrl;

- (NSString *)cdnUrl;

//默认60s
- (NSTimeInterval)requestTimeoutInterval;

- (nullable id)requestArgument;

- (id)cacheFileNameFilterForRequestArgument:(id)argument;

- (RequestMethod)requestMethod;

- (RequestSerializerType)requestSerializerType;

- (ResponseSerializerType)responseSerializerType;

- (nullable NSArray<NSString *> *)requestAuthorizationHeaderFieldArray;

- (nullable NSDictionary<NSString *, NSString *> *)requestHeaderFieldValueDictionary;

- (nullable NSURLRequest *)buildCustomUrlRequest;

- (BOOL)useCDN;

- (BOOL)allowsCellularAccess;

- (nullable id)jsonValidator;

- (BOOL)statusCodeValidator;

@end
    
    
NS_ASSUME_NONNULL_END
